package org.example.hansp.draw;

import javax.swing.*;
import java.awt.*;

public class DrawCircle extends JFrame {//JFrame 对应窗口，可以理解为一个画框
    private MyPanel panel = null;

    public static void main(String[] args) {
        new DrawCircle();
    }

    public DrawCircle() {
        //初始化面板
        panel = new MyPanel();
        //把面板放入窗口
        this.add(panel);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //设置窗口大小
        this.setSize(500, 500);
        this.setVisible(true);

    }
}

/*
 * MyPanel对象就是一个画板
 * Graphics g  把g 理解成一支画笔
 * Graphics 提供了很多绘图方法 */
class MyPanel extends JPanel {
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.drawOval(90, 90, 300, 300);
        g.setColor(Color.RED);
        g.draw3DRect(0,0,100,100,true);
        System.out.println("方法被调用");
    }
}